<?php 
if($_GET['operation']=="add" or $_GET['operation']=="edit")
{
	if($_POST['act'])
	{
		unset($_GET['s']);
		unset($_GET['m']);
		unset($_GET['operation']);
		if($_POST['act'] == 'save'){//新增
			$sql = "insert into ".SHARESPECIALTPL." (title,tpl_con,status) values('{$_POST['title']}','{$_POST['tpl_con']}','{$_POST['status']}')";
			$db->query($sql);
		}
		if($_POST['act'] == 'edit' && $_POST['id']>0){//编辑
			$sql = "update ".SHARESPECIALTPL." set title='{$_POST['title']}',tpl_con='{$_POST['tpl_con']}',status='{$_POST['status']}' where id='{$_POST['id']}'";
			$db->query($sql);
		}
		unset($_GET['editid']);
		$getstr=implode('&',convert($_GET));
		msg("?m=share_special&s=share_special_tpl.php&$getstr");
	}
	//模板信息
	if($_GET['editid'] and is_numeric($_GET['editid']))
	{
		$sql="select * from ".SHARESPECIALTPL." where id='$_GET[editid]'";
		$db->query($sql);
		$de=$db->fetchRow();
	}
}


else
{
	//删除模板
	if($_GET['delid'])
	{
		$sql="update ".SHARESPECIALTPL."  set status=-1 where id='$_GET[delid]'";
		$db->query($sql);
		unset($_GET['delid']);
		$getstr=implode('&',convert($_GET));
		msg("?m=share_special&s=share_special_tpl.php&$getstr");
	}
	if($_POST['act']=='op')
	{
		if(is_array($_POST['chk']))
		{
			$id=implode(",",$_POST['chk']);
			$sql="update ".SHARESPECIALTPL."  set status=-1 where id in ($id)";
			$db->query($sql);
		}
		msg("?m=share_special&s=share_special_tpl.php");
	}
	//获取活动
	$where = "";
	if(($_GET['statu']!="") && ($_GET['statu']>=0)){
		$where .=" and status='$_GET[statu]'";
	}else{
		$where .=" and status>-1";
	}

	$sql="select * from ".SHARESPECIALTPL." where 1".$where;
	$db->query($sql);
	$de['list']=$db->getRows();
}
$condTemp = $_GET;
unset($condTemp['m']);
unset($condTemp['s']);
$cond = "";
if(count($condTemp)){
	$cond = "&".http_build_query($condTemp);
}
$tpl->assign("cond",$cond);
$tpl->assign("de",$de);
$tpl->assign("config",$config);
$tpl->display('share_special_tpl.htm');
?>